/*
 * $Id: IIPResponseParser.java,v 1.2 2009/03/13 19:08:46 navdeep_mahajan Exp $
 * 
 * Copyright (C) 2006 General Electric Company. All Rights Reserved.
 * 
 * This software is the confidential and proprietary information of the General
 * Electric Company (GE). You shall not disclose this software and shall use it
 * only in accordance with the terms of the license agreement you entered into
 * with GE.
 * 
 * GE MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
 * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
 * NON-INFRINGEMENT. GE SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
 * AS A RESULT OF USING, MODIFYING, OR DISTRIBUTING THIS SOFTWARE OR ITS
 * DERIVATIVES.
 */
package com.ge.healthcare.autosc.processor.iip.comm;

import com.ge.healthcare.autosc.common.ASCUtil;
import com.ge.healthcare.autosc.processor.iip.comm.vo.FileInfo;

/**
 * @author 212042764
 * 
 */
public class IIPResponseParser {

	private static final String SPACE = " ";

	/**
	 * Don't instantiate me
	 */
	private IIPResponseParser() {
		super();
	}

	public static FileInfo parseFileInformation(String response) {
		if (ASCUtil.isNullOrEmpty(response)) {
			return null;
		}
		response = response.trim();
		final String[] args = response.split(SPACE);
		FileInfo fileInfo = new FileInfo();
		int iCount = 0;
		if (iCount < args.length) {
			fileInfo.setExitCode(Integer.parseInt(args[iCount++]));
		}
		if (iCount < args.length) {
			fileInfo.setStdoutPath(args[iCount++]);
		}
		if (iCount < args.length) {
			fileInfo.setStdoutSize(Integer.parseInt(args[iCount++]));
		}
		if (iCount < args.length) {
			fileInfo.setStderrPath(args[iCount++]);
		}
		if (iCount < args.length) {
			fileInfo.setStderrSize(Integer.parseInt(args[iCount++]));
			// Now that i have been able to get all required information out i
			// can mark the file info as valid
			fileInfo.setValid(true);
		}
		return fileInfo;
	}

}
